﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YLW.Plat.Jhfw.HL7V3.XSDModels.PRSC_IN100000UV;
using YLW.Plat.Jhfw.Model.JhfwHypb;

namespace YLW.Plat.Jhfw.HL7V3.V3Message
{
    public class V3_PRSC_IN100000UV
    {
        public static string SourceAndScheduleInfoQuery(GetJhfwHypbListIn jsonData, string id_extension, string sender_name, string receiver_name)
        {
            string hl7Xml = string.Empty;

            if (jsonData == null)
            {
                return hl7Xml;
            }

            //根据XML XSD构建HL7 XML消息格式

            //创建根对象
            var xmlRoot = new PRSC_IN100000UV
            {
                ITSVersion = "XML_1.0",
                id1 = new id1 { root = "2.16.156.10011.2.5.1.1", extension = id_extension },
                creationTime = new creationTime { value = DateTime.Now.ToString("yyyyMMddHHmmss") },
                interactionId = new interactionId { root = "2.16.156.10011.2.5.1.2", extension = "PRSC_IN100000UV" },
                processingCode = new processingCode { code = "P" },
                processingModeCode = new processingModeCode(),
                acceptAckCode = new acceptAckCode { code = "AL" },
                receiver = new receiver
                {
                    typeCode = "RCV",
                    device1 = new device1
                    {
                        classCode = "DEV",
                        determinerCode = "INSTANCE",
                        id1 = new id1
                        {
                            item = new item
                            {
                                root = "2.16.156.10011.2.5.1.3",
                                extension = receiver_name
                            }
                        }
                    }
                },
                sender = new sender
                {
                    typeCode = "SND",
                    device1 = new device1
                    {
                        classCode = "DEV",
                        determinerCode = "INSTANCE",
                        id1 = new id1
                        {
                            item = new item
                            {
                                root = "2.16.156.10011.2.5.1.3",
                                extension = sender_name
                            }
                        }
                    }
                },
                controlActProcess = new controlActProcess
                {
                    classCode = "CACT",
                    moodCode = "EVN",
                    queryByParameter = new queryByParameter
                    {
                        queryId = new queryId { extension = id_extension },
                        statusCode = new statusCode(),
                        scheduleId = new value
                        {
                            value1 = new value1
                            {
                                Items = new object[]
                                {
                                    new item{ root="2.16.156.10011.2.5.1.20", extension=jsonData.pbid }
                                }
                            }
                        },
                        effectiveTime = new value
                        {
                            value1 = new value1
                            {
                                Items = new object[]
                                {
                                    new low{ value=jsonData.kssj },
                                    new high{ value=jsonData.jssj }
                                }
                            }
                        },
                        resourceDept = new resourceDept
                        {
                            value1 = new value1
                            {
                                Items = new object[]
                                {
                                        new item{ root="2.16.156.10011.1.26", extension=jsonData.deptid }
                                    }
                            },
                            semanticsText = new semanticsText
                            {
                                value = jsonData.deptname
                            }
                        },
                        employeeId = new employeeId
                        {
                            value1 = new value1
                            {
                                Items = new object[]
                                {
                                    new item{ root="2.16.156.10011.1.4", extension=jsonData.empid },
                                    new item{ root="2.16.156.10011.1.3", extension=jsonData.sfzh }
                                }
                            },
                            semanticsText = new semanticsText
                            {
                                value = jsonData.empname
                            }
                        },
                        slotType = new value
                        {
                            value1 = new value1
                            {
                                code = jsonData.fsdzylx,
                                codeSystem = "2.16.156.10011.2.5.1.22",
                                codeSystemName = "排班资源类型代码",
                                Items = new object[]
                               {
                                   new displayName{ value=jsonData.fsdzymc }
                               }
                            }
                        },
                        extension = new extension
                        {
                            page = new value { value1 = new value1 { Text = new string[] { jsonData.page.ToString() } } },
                            percount = new value { value1 = new value1 { Text = new string[] { jsonData.percount.ToString() } } },
                            hoscode = new value { value1 = new value1 { Text = new string[] { jsonData.hoscode } } },
                            pbid = new value { value1 = new value1 { Text = new string[] { jsonData.pbid } } },
                            deptid = new value { value1 = new value1 { Text = new string[] { jsonData.deptid } } },
                            deptname = new value { value1 = new value1 { Text = new string[] { jsonData.deptname } } },
                            empid = new value { value1 = new value1 { Text = new string[] { jsonData.empid } } },
                            empname = new value { value1 = new value1 { Text = new string[] { jsonData.empname } } },
                            sfzh = new value { value1 = new value1 { Text = new string[] { jsonData.sfzh } } },
                            fsdzylx = new value { value1 = new value1 { Text = new string[] { jsonData.fsdzylx } } },
                            fsdzymc = new value { value1 = new value1 { Text = new string[] { jsonData.fsdzymc } } },
                            kssj = new value { value1 = new value1 { Text = new string[] { jsonData.kssj } } },
                            jssj = new value { value1 = new value1 { Text = new string[] { jsonData.jssj } } }
                        }
                    }
                }
            };

            hl7Xml = HL7V3Helper.SerializeToXml(xmlRoot);

            return hl7Xml;
        }
    }
}
